import 'package:flutter/material.dart';
import 'package:framework/config/constants.dart';

/// 单选多选的view
class ChoiceItemView extends StatelessWidget {
  final String text;
  final bool isSelected;
  final VoidCallback onTap;
  final Color? selectedColor;
  final Color? unselectedColor;
  final Color? borderColor;

  const ChoiceItemView({
    Key? key,
    required this.text,
    required this.isSelected,
    required this.onTap,
    this.selectedColor,
    this.unselectedColor,
    this.borderColor,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final defaultSelectedColor = theme.primaryColor;
    final defaultUnselectedColor = Colors.grey.shade200;

    return InkWell(
      onTap: onTap,
      borderRadius: BorderRadius.circular(3),
      child: Container(
        padding: const EdgeInsets.symmetric(
            horizontal: Constants.px_10, vertical: Constants.px_4),
        decoration: BoxDecoration(
          color: isSelected
              ? selectedColor ?? defaultSelectedColor.withOpacity(0.2)
              : unselectedColor ?? defaultUnselectedColor,
          borderRadius: BorderRadius.circular(3),
          border: Border.all(
            color: isSelected
                ? borderColor ?? defaultSelectedColor
                : Colors.transparent,
            width: 0.5,
          ),
        ),
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text(text,
                style: TextStyle(
                    color: Colors.black,
                    fontSize: 10,
                    fontWeight: FontWeight.w500))
          ],
        ),
      ),
    );
  }
}
